﻿using JiebaNet.Segmenter;
using ManagementApi.Models.Cms;
using ManagementApi.Models.Cms.Request;
using ManagementApi.Services.Cms.Request;
using Modules.Base;
using Modules.CheckIn;
using Modules.Corp;
using Modules.FaceScan;
using Modules.FaceScan.Entitys;
using Modules.Person;
using Modules.Project;
using Modules.Project.Entitys;
using Modules.Reports;
using Newtonsoft.Json;
using PmSoft;
using PmSoft.ApplicationContext;
using PmSoft.Entity;
using PmSoft.Events;
using PmSoft.Exceptions;
using PmSoft.FileStorage;
using PmSoft.Utilities;
using System.Net;
using static Modules.Person.PersonConstants;
using static Modules.Project.ProjectConstants;
using static Modules.Project.ProjectLockLogConstants;

namespace Modules.Cms;

/// <summary>
/// 实名制和一体化业务支撑Service
/// </summary>
[UseDI(ServiceLifetime.Scoped)]
public class CmsSupportService
{
    private readonly IApplicationContext applicationContext;
    private readonly IConfiguration configuration;
    private readonly ILogger logger;
    private readonly IFileStorage fileStorage;
    private readonly PersonService personService;
    private readonly FacePhotoService personFaceService;
    private readonly ProjectService projectService;
    private readonly ProjectCorpService projectCorpService;
    private readonly ProjectGroupService projectGroupService;
    private readonly ProjectGroupMemberService projectGroupMemberService;
    private readonly ProjectLockLogService projectLockLogService;
    private readonly ReportProjectMonthService reportProjectMonthService;
    private readonly CheckinWorkHoursService checkinWorkHoursService;
    private readonly CorpService corpService;
    private readonly ProjectCheckinPushLogService projectCheckinPushLogService;
    private readonly IEventBus eventBus;

    #region 全局变量

    private readonly string apiUrl = "";
    private readonly string userName;
    private static string token = "";

    #endregion 全局变量

    public CmsSupportService(IApplicationContext applicationContext, IConfiguration configuration, IFileStorage fileStorage, PersonService personService, FacePhotoService personFaceService, ProjectService projectService, ProjectCorpService projectCorpService, ProjectGroupService projectGroupService, ProjectGroupMemberService projectGroupMemberService, ILogger<CmsSupportService> logger, ProjectLockLogService projectLockLogService, ReportProjectMonthService reportProjectMonthService, CheckinWorkHoursService checkinWorkHoursService, IEventBus eventBus, CorpService corpService, ProjectCheckinPushLogService projectCheckinPushLogService)
    {
        this.applicationContext = applicationContext;
        this.logger = logger;
        this.configuration = configuration;
        this.fileStorage = fileStorage;
        this.personService = personService;
        this.personFaceService = personFaceService;
        this.projectService = projectService;
        this.projectCorpService = projectCorpService;
        this.projectGroupService = projectGroupService;
        this.projectGroupMemberService = projectGroupMemberService;
        this.reportProjectMonthService = reportProjectMonthService;
        this.projectLockLogService = projectLockLogService;
        this.checkinWorkHoursService = checkinWorkHoursService;
        this.eventBus = eventBus;
        this.corpService = corpService;
        this.projectCheckinPushLogService = projectCheckinPushLogService;
        apiUrl = configuration.GetValue<string>("CmsWepApi:Url") ?? "";
        userName = configuration.GetValue<string>("CmsWepApi:UserName") ?? "";
    }

    /// <summary>
    /// 获取token
    /// </summary>
    /// <returns></returns>
    public string GetToken()
    {
        if (token != "")
            return token;
        HttpResult result = HttpHelper.GetAsync($"{apiUrl}/SmzV2/GetToken?name={userName}").GetAwaiter().GetResult();
        if (result.Code == HttpStatusCode.OK)
        {
            CmsResult apiResult = JsonConvert.DeserializeObject<CmsResult>(result.Data.ToString() ?? "") ?? new CmsResult();
            token = $"Bearer {apiResult.data}";
            return token ?? "";
        }
        return "";
    }

    /// <summary>
    /// 项目信息推送到一体化平台
    /// </summary>
    /// <param name="projectInfo"></param>
    public void PublishProject(ProjectInfo projectInfo)
    {
        PublishProjectReq req = new()
        {
            PrjNum = projectInfo.PrjNum,
            PrjName = projectInfo.Name,
            BuildCorpCode = projectInfo.BuildCorpCode,
            BuilderLicenceNum = projectInfo.BuilderLicences ?? ""
        };
        HttpResult result = HttpHelper.PostAsync($"{apiUrl}/SmzV2/PublishProject", JsonConvert.SerializeObject(req), "Authorization", GetToken()).GetAwaiter().GetResult();
        if (result.Code == HttpStatusCode.OK)
            logger.LogInformation($"项目{req.PrjNum},推送到一体化平台成功");
        else
        {
            logger.LogError($"项目{req.PrjNum},推送到一体化平台失败，原因：{result.Data}");
            throw new BusinessException($"项目{req.PrjNum},推送到一体化平台失败，原因：{result.Data}");
        }
    }

    /// <summary>
    /// 同步人员信息(无事务)
    /// </summary>
    /// <param name="projectInfo"></param>
    /// <param name="person"></param>
    /// <param name="personInfos"></param>
    /// <param name="personFaces"></param>
    /// <param name="projectCorps"></param>
    /// <param name="projectGroups"></param>
    /// <exception cref="BusinessException"></exception>
    public void SyncPersonNoTransaction(ProjectInfo projectInfo, PrjPersonInfoResult person, IEnumerable<PersonInfo> personInfos, IEnumerable<FacePhoto> personFaces, IEnumerable<ProjectCorp> projectCorps, IEnumerable<ProjectGroup> projectGroups)
    {
        #region 给人员基础信息表赋值【person】

        PersonInfo personInfo = new();
        //无数据，则需要新增人员信息
        if (personInfos.FirstOrDefault(a => a.CardNumber == person.GRIDCard) == null)
        {
            personInfo = new()
            {
                Name = person.GRName,
                CardNumber = person.GRIDCard,
                Gender = (int)person.Gender,
                Birthday = person.Birthday,
                CreateTime = person.CreateTime
            };
            personService.CreatePersonInfo(personInfo);
        }

        #endregion 给人员基础信息表赋值【person】

        #region 给人员核验照片赋值【person_face】，并且上传到minio

        //无数据，则需要新增人员身份证及比对照片表
        if (personFaces.FirstOrDefault(a => a.IdCard == person.GRIDCard) == null)
        {
            if (string.IsNullOrEmpty(person.GRPhoto))
            {
                applicationContext.Transaction.Abort();
                logger.LogError($"人员{person.GRName},没有身份证照片");
                throw new BusinessException($"人员{person.GRName},没有身份证照片");
            }

            FacePhoto personFace = new()
            {
                PhotoType = PhotoType.Person,
                IdCard = person.GRIDCard,
                IdCardPhoto = $"{person.GRIDCard}/idCard_V1.jpg",
                IdCardPhotover = 1,
                IdCardPhotoTime = DateTime.Now,
                CreateTime = DateTime.Now
            };
            if (!string.IsNullOrEmpty(person.GRTemplatePhoto))
            {
                personFace.VerifyPhoto = $"{person.GRIDCard}/Appauth_{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.jpg";
                personFace.VerifyPhotover = 1;
                personFace.VerifyPhotoTime = DateTime.Now;

                #region 上传到minio

                byte[] picDataTemplate = Base64Utilities.ConverBase64(person.GRTemplatePhoto);
                string objectNameTemplate = personFace.VerifyPhoto;
                fileStorage.PutFileAsync(FileBuckets.Person, objectNameTemplate, picDataTemplate).GetAwaiter().GetResult();

                #endregion 上传到minio
            }

            personFaceService.Insert(personFace);

            #region 上传到minio

            byte[] picData = Base64Utilities.ConverBase64(person.GRPhoto);
            string objectName = personFace.IdCardPhoto;
            fileStorage.PutFileAsync(FileBuckets.Person, objectName, picData).GetAwaiter().GetResult();

            #endregion 上传到minio
        }

        #endregion 给人员核验照片赋值【person_face】，并且上传到minio

        #region 给人员班组信息赋值【project_group_member】

        //只能赋值管理组人员，除了监理负责人 ，都是赋值给总包企业，监理负责人赋值给监理企业

        if (person.GWName.AsPostCategory() != 管理岗位类型.总监理工程师 && person.GWName.AsPostCategory() != 管理岗位类型.总监理工程师代表)
        {
            //查询总包是否有管理组
            ProjectGroup? projectGroup = projectGroups.FirstOrDefault(a => a.CorpId == projectInfo.LumpContractorCorpId);
            if (projectGroup != null)
            {
                ProjectGroupMember projectGroupMember = new()
                {
                    ProjectId = projectInfo.ProjectId,
                    GroupId = projectGroup.GroupId,
                    CorpId = projectInfo.LumpContractorCorpId,
                    PersonId = personInfo.PersonId,
                    PostCategory = person.GWName.AsPostCategory(),
                    CreateTime = personInfo.CreateTime,
                    StartDate = DateTime.Now,
                    Status = 进出场状态.进场,
                    IsManager = true
                };

                projectGroupMemberService.Create(projectGroupMember);
            }
        }

        var projectCorp = projectCorps.FirstOrDefault(a => a.Role == 项目参建单位类型.监理);
        if (projectCorp != null)
        {
            if (person.GWName.AsPostCategory() == 管理岗位类型.总监理工程师 || person.GWName.AsPostCategory() == 管理岗位类型.总监理工程师代表)
            {
                //查询监理是否有管理组
                ProjectGroup? projectGroup = projectGroups.FirstOrDefault(a => a.CorpId == projectCorp.CorpId);
                if (projectGroup != null)
                {
                    ProjectGroupMember projectGroupMember = new()
                    {
                        ProjectId = projectInfo.ProjectId,
                        GroupId = projectGroup.GroupId,
                        CorpId = projectCorp.CorpId,
                        PersonId = personInfo.PersonId,
                        PostCategory = person.GWName.AsPostCategory(),
                        CreateTime = personInfo.CreateTime,
                        StartDate = DateTime.Now,
                        Status = 进出场状态.进场,
                        IsManager = true
                    };

                    projectGroupMemberService.Create(projectGroupMember);
                }
            }
        }

        #endregion 给人员班组信息赋值【project_group_member】
    }

    /// <summary>
    /// 项目信息同步
    /// </summary>
    /// <param name="projectInfo"></param>
    /// <exception cref="BusinessException"></exception>
    public void SyncProject(ProjectInfo projectInfo)
    {
        HttpResult result = HttpHelper.GetAsync($"{apiUrl}/SmzV2/ReadProjects?builderLicenceNum={projectInfo.BuilderLicences}", "Authorization", GetToken()).GetAwaiter().GetResult();
        if (result.Code != HttpStatusCode.OK)
        {
            logger.LogError($"{projectInfo.BuilderLicences} 项目信息同步失败,原因：{result.Data}");
            throw new BusinessException($"项目信息同步失败,原因：{result.Data}");
        }
        CmsResult apiResult = JsonConvert.DeserializeObject<CmsResult>(result.Data.ToString() ?? "") ?? new CmsResult();
        ProjectInfoResult? projectInfoResult = JsonConvert.DeserializeObject<ProjectInfoResult>(apiResult.data?.ToString() ?? "");
        if (projectInfoResult == null)
        {
            logger.LogError($"没有查询到项目{projectInfo.BuilderLicences}信息");
            throw new BusinessException($"没有查询到项目{projectInfo.BuilderLicences}信息");
        }

        #region 对比项目名称相似度

        var segmenter = new JiebaSegmenter();
        var words1 = segmenter.Cut(projectInfoResult.PrjName);
        var words2 = segmenter.Cut(projectInfo.Name);

        // 项目名称相似度计算
        double similarityScore = StringSimilarity.CalculateCosineSimilarity(words1, words2);
        if (similarityScore < 0.7)
        {
            logger.LogError($"实名制平台项目名称与施工许可证项目名称相似度低于70%，不能进行关联");
            throw new BusinessException($"实名制平台项目名称与施工许可证项目名称相似度低于70%，不能进行关联");
        }

        #endregion 对比项目名称相似度

        IEnumerable<PrjPersonInfoResult> persons = projectInfoResult.Persons;
        IEnumerable<PersonInfo> personInfos = personService.GetPersonsByCardNumbers(persons.Select(a => a.GRIDCard));
        IEnumerable<FacePhoto> personFaces = personFaceService.GetPersonFacesByIdCards(persons.Select(a => a.GRIDCard));
        IEnumerable<ProjectCorp> projectCorps = projectCorpService.GetProjectCorpsByProjectId(projectInfo.ProjectId);
        //查询总包和监理管理班组
        IEnumerable<ProjectGroup> projectGroups = projectGroupService.GetProjectGroupsByProjectId(projectInfo.ProjectId).Where(a => a.IsManagerGroup == true);
        try
        {
            applicationContext.Transaction.Begin();
            foreach (var item in persons)
            {
                SyncPersonNoTransaction(projectInfo, item, personInfos, personFaces, projectCorps, projectGroups);

                #region 修改项目同步状态为已同步

                projectInfo.IsSync = true;
                projectService.Update(projectInfo);

                #endregion 修改项目同步状态为已同步
            }

            applicationContext.Transaction.Complete();
            //将项目信息推送给实名制平台
            PublishProject(projectInfo);
        }
        catch (Exception ex)
        {
            applicationContext.Transaction.Abort();
            logger.LogError($"项目{projectInfo.PrjNum},同步失败,原因：{ex.Message}");
            throw new BusinessException($"项目{projectInfo.PrjNum},同步失败,原因：{ex.Message}");
        }
    }

    /// <summary>
    /// 冻结项目
    /// </summary>
    /// <param name="projectLock"></param>
    public void ProjectLock(ProjectLockReq projectLock)
    {
        ProjectLockLog? entity = projectLockLogService.GetProjectLockLogByCode(projectLock.OrgID);
        if (entity == null)
        {
            logger.LogError($"编号{projectLock.OrgID},没有查询到冻结记录");
            return;
        }
        entity.PushTime = DateTime.Now;
        HttpResult result = HttpHelper.PutAsync($"{apiUrl}/SmzV2/ProjectLock", JsonConvert.SerializeObject(projectLock), "Authorization", GetToken()).GetAwaiter().GetResult();
        if (result.Code == HttpStatusCode.OK)
        {
            logger.LogInformation($"编号{projectLock.OrgID},冻结信息推送到一体化平台完成");
            CmsResult? cmsResult = JsonConvert.DeserializeObject<CmsResult>(result.Data.ToString());
            if (cmsResult != null)
            {
                if (cmsResult.success)
                {
                    logger.LogInformation($"编号{projectLock.OrgID},在一体化平台冻结成功");
                    entity.PushResult = 1;
                }
                else
                {
                    logger.LogInformation($"编号{projectLock.OrgID},在一体化平台冻结失败，原因：{cmsResult.msg}");
                    entity.PushResult = 0;
                }
                entity.HasPush = true;
                entity.PushResponse = cmsResult.msg;
                entity.PushResponseTime = DateTime.Now;
                projectLockLogService.Update(entity);
            }
        }
        else
        {
            logger.LogError($"编号{projectLock.OrgID},冻结信息推送到一体化平台失败，原因：{result.ErrorMsg}");
        }
    }

    /// <summary>
    /// 解冻项目
    /// </summary>
    /// <param name="code"></param>
    public void ProjectUnlock(string code)
    {
        ProjectLockLog? entity = projectLockLogService.GetProjectLockLogByCode(code);
        if (entity == null)
        {
            logger.LogError($"编号{code},没有查询到冻结记录");
            throw new BusinessException($"编号{code},没有查询到冻结记录");
        }
        entity.PushTime = DateTime.Now;
        HttpResult result = HttpHelper.PutAsync($"{apiUrl}/SmzV2/ProjectUnlock?orgId={code}", "", "Authorization", GetToken()).GetAwaiter().GetResult();
        if (result.Code == HttpStatusCode.OK)
        {
            logger.LogInformation($"编号{code},解冻信息推送到一体化平台完成");
            CmsResult? cmsResult = JsonConvert.DeserializeObject<CmsResult>(result.Data.ToString());
            if (cmsResult != null)
            {
                if (cmsResult.success)
                {
                    logger.LogInformation($"编号{code},在一体化平台解冻成功");
                    entity.PushResult = 1;
                    entity.UnlockTime = DateTime.Now;
                }
                else
                {
                    logger.LogInformation($"编号{code},在一体化平台解冻失败，原因：{cmsResult.msg}");
                    entity.PushResult = 0;
                }
                entity.HasPush = true;
                entity.PushResponse = cmsResult.msg;
                entity.PushResponseTime = DateTime.Now;
                entity.DataSourse = 解锁数据来源.手动;
                projectLockLogService.Update(entity);
            }
        }
        else
        {
            logger.LogError($"编号{code},解冻信息推送到一体化平台失败，原因：{result.ErrorMsg}");
            throw new BusinessException($"编号{code},解冻信息推送到一体化平台失败，原因：{result.ErrorMsg}");
        }
    }

    /// <summary>
    /// 实名制平台向一体化平台推送项目4个状态
    /// </summary>
    /// <param name="projectId"></param>
    public void ProjectStatus(int projectId)
    {
        ProjectInfo? projectInfo = projectService.GetProjectInfo(projectId);
        ReportProjectMonth? reportProjectMonth = reportProjectMonthService.GetReportProjectMonthByProjectIdAndMonth(projectId, Convert.ToInt32(DateTime.Now.ToString("yyyyMM")));
        if (projectInfo == null)
        {
            logger.LogError($"项目{projectId}信息不存在");
            throw new BusinessException($"项目{projectId}信息不存在");
        }
        if (reportProjectMonth == null)
        {
            logger.LogError($"项目月报表{projectId}信息不存在");
            throw new BusinessException($"项目月报表{projectId}信息不存在");
        }
        ProjectStatusReq projectStatusReq = new();
        projectStatusReq.BuildCode = projectInfo.PrjNum;

        if (reportProjectMonth.SpecialAccountStatus == 落实状态.已落实)
            projectStatusReq.SpecialAccountStatus = SpecialAccountStatusType.Y;
        else
            projectStatusReq.SpecialAccountStatus = SpecialAccountStatusType.N;

        if (reportProjectMonth.CheckinStatus == 落实状态.未落实)
            projectStatusReq.CheckingInStatus = CheckingInStatusType.N;
        else if (reportProjectMonth.CheckinStatus == 落实状态.半落实)
            projectStatusReq.CheckingInStatus = CheckingInStatusType.O;
        else if (reportProjectMonth.CheckinStatus == 落实状态.已落实)
            projectStatusReq.CheckingInStatus = CheckingInStatusType.Y;

        if (reportProjectMonth.WageStatus == 落实状态.未落实)
            projectStatusReq.SubstituteStatus = SubstituteStatusType.N;
        else if (reportProjectMonth.WageStatus == 落实状态.半落实)
            projectStatusReq.SubstituteStatus = SubstituteStatusType.O;
        else if (reportProjectMonth.WageStatus == 落实状态.已落实)
            projectStatusReq.SubstituteStatus = SubstituteStatusType.Y;

        if (projectInfo.PrjStatus == 项目状态.筹备)
            projectStatusReq.BuildingStatus = BuildingStatusType.Null;
        else if (projectInfo.PrjStatus == 项目状态.在建)
            projectStatusReq.BuildingStatus = BuildingStatusType.Building;
        else if (projectInfo.PrjStatus == 项目状态.停工)
            projectStatusReq.BuildingStatus = BuildingStatusType.Stopped;
        else if (projectInfo.PrjStatus == 项目状态.完工)
            projectStatusReq.BuildingStatus = BuildingStatusType.Completed;

        logger.LogInformation($"推送到一体化平台四个状态，参数{JsonConvert.SerializeObject(projectStatusReq)}");
        HttpResult result = HttpHelper.PutAsync($"{apiUrl}/SmzV2/ProjectStatus", JsonConvert.SerializeObject(projectStatusReq), "Authorization", GetToken()).GetAwaiter().GetResult();
        if (result.Code == HttpStatusCode.OK)
        {
            logger.LogInformation($"项目id{projectId},推送到一体化平台四个状态完成");
            CmsResult? cmsResult = JsonConvert.DeserializeObject<CmsResult>(result.Data.ToString());
            logger.LogInformation($"一体化返回信息：{cmsResult.data}");
        }
        else
        {
            logger.LogError($"项目id{projectId},推送到一体化平台四个状态失败，原因：{result.ErrorMsg}");
            throw new BusinessException($"项目id{projectId},推送到一体化平台四个状态失败，原因：{result.ErrorMsg}");
        }
    }

    /// <summary>
    /// 推送项目考勤人员信息（关键岗位）
    /// </summary>
    /// <param name="projectId"></param>
    /// <param name="month"></param>
    /// <exception cref="BusinessException"></exception>
    //public void ProjectPersonAttendanceInfos(int projectId, int month)
    //{
    //    ProjectInfo? projectInfo = projectService.GetProjectInfo(projectId);
    //    ReportProjectMonth? reportProjectMonth = reportProjectMonthService.GetReportProjectMonthByProjectIdAndMonth(projectId, month);
    //    if (projectInfo == null)
    //    {
    //        logger.LogError($"项目{projectId}信息不存在");
    //        throw new BusinessException($"项目{projectId}信息不存在");
    //    }
    //    if (reportProjectMonth == null)
    //    {
    //        logger.LogError($"项目月报表{projectId}信息不存在");
    //        throw new BusinessException($"项目月报表{projectId}信息不存在");
    //    }
    //    ProjectPersonAttendanceInfoReq req = new()
    //    {
    //        BuildCode = projectInfo.PrjNum,
    //        ProjectName = projectInfo.Name,
    //        AttendanceMonth = month.ToString()
    //    };

    // IEnumerable<ProjectGroupMember> projectGroupMembers =
    // projectGroupMemberService.GetProjectGroupMembersByGroupId(projectInfo.ProjectId);
    // IEnumerable<CheckinWorkHours> checkinWorkHours =
    // checkinWorkHoursService.GetCheckinWorks(month, projectGroupMembers.Select(m => m.Id));

    // IEnumerable<CorpInfo> corpInfos = corpService.GetCorpInfos(projectGroupMembers.Select(a =>
    // a.CorpId)); IEnumerable<ProjectCorp> projectCorps =
    // projectCorpService.GetProjectCorpsByProjectId(projectId); IEnumerable<PersonInfo> personInfos
    // = personService.GetPersons(checkinWorkHours.Select(a => a.PersonId));

    // List<PersonAttendanceInfo> personAttendanceInfos = new(); foreach (var item in
    // checkinWorkHours) { ProjectGroupMember? projectGroupMember =
    // projectGroupMembers.FirstOrDefault(a => a.Id == item.MemberId); if (projectGroupMember ==
    // null) continue; CorpInfo? corp = corpInfos.FirstOrDefault(a => a.CorpId ==
    // projectGroupMember.CorpId); if (corp == null) continue; ProjectCorp? projectCorp =
    // projectCorps.FirstOrDefault(a => a.ProjectId == projectGroupMember.ProjectId && a.CorpId ==
    // projectGroupMember.CorpId); if (projectCorp == null) continue; PersonInfo? personInfo =
    // personInfos.FirstOrDefault(a => a.PersonId == item.PersonId); if (personInfo == null)
    // continue; PersonAttendanceInfo info = new() { CorpCode = corp.Code, CorpName = corp.Name,
    // PersonName = personInfo.Name, IdCard = personInfo.CardNumber, AttendanceDays =
    // item.CheckinDay, PostName = projectGroupMember.PostCategory.GetDescription(string.Empty) };

    // personAttendanceInfos.Add(info); }

    // if (personAttendanceInfos.Count > 0) {
    // logger.LogInformation($"推送项目考勤人员信息，参数{JsonConvert.SerializeObject(personAttendanceInfos)}");
    // HttpResult result = HttpHelper.PostAsync($"{apiUrl}/SmzV2/ProjectPersonAttendanceInfos",
    // JsonConvert.SerializeObject(personAttendanceInfos), "Authorization",
    // GetToken()).GetAwaiter().GetResult(); if (result.Code == HttpStatusCode.OK) {
    // logger.LogInformation($"项目id{projectId},推送项目考勤人员信息完成"); CmsResult? cmsResult =
    // JsonConvert.DeserializeObject<CmsResult>(result.Data.ToString()); logger.LogInformation($"一体化返回信息：{cmsResult.data}");

    //            //写入推送记录
    //            ProjectCheckinPushLog log = new()
    //            {
    //                ProjectId = projectId,
    //                Month = month,
    //                PushData = JsonConvert.SerializeObject(personAttendanceInfos),
    //                HasPush = true,
    //                CreateTime = DateTime.Now
    //            };
    //            projectCheckinPushLogService.Create(log);
    //        }
    //        else
    //        {
    //            logger.LogError($"项目id{projectId},推送项目考勤人员信息失败，原因：{result.ErrorMsg}");
    //            throw new BusinessException($"项目id{projectId},推送项目考勤人员信息失败，原因：{result.ErrorMsg}");
    //        }
    //    }
    //    else
    //    {
    //        logger.LogError($"项目id{projectId},推送项目考勤人员信息失败，原因：当前项目没有考勤数据");
    //        //写入推送记录
    //        ProjectCheckinPushLog log = new()
    //        {
    //            ProjectId = projectId,
    //            Month = month,
    //            HasPush = false,
    //            CreateTime = DateTime.Now
    //        };
    //        projectCheckinPushLogService.Create(log);
    //    }
    //}
}